import operate from '@dfeidao/atom-nodejs/db/operate';
import log from '@dfeidao/atom-nodejs/logger/log';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import sys_date from '@dfeidao/atom-nodejs/msg/sys-date';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../atom/config';

interface Message {
	contents_leave: string;
	teacher_no: string;
	time_length: number;
	leave_type: string;
	start_time: number;
	end_time: number;
	check_status: string;
	teacher_name: string;
	productid: string;

	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:app-teacher-leave/s002,action_id:' + action_id);
	const num1 = await doc_code(action_id, session_id, systemid, 'BM0015995', '', 1);
	const teacher_leave_num1 = num1.result;
	const submission_time1 = sys_date(action_id, session_id);
	const { insert, exec } = operate(action_id, session_id, systemid);
	insert('teacher_leave', { teacher_leave_num: teacher_leave_num1, submission_time: submission_time1, teacher_leave_content: message.contents_leave, teacher_no: message.teacher_no, leave_days: message.time_length, leave_type: message.leave_type, start_time: message.start_time, finish_time: message.end_time, auditor_status: message.check_status, teacher_name: message.teacher_name, productid: message.productid });

	const ret = await exec();


	log('Service end path:app-teacher-leave/s002,action_id:' + action_id);
	return {
		data: ret
	};
}
